package com.bristua.barcode.customer.controller;

import com.bristua.barcode.common.bean.Result;
import com.bristua.barcode.common.util.HandleResultUtil;
import com.bristua.barcode.common.util.MD5Util;
import com.bristua.barcode.customer.biz.GetCustomerIdBiz;
import com.bristua.barcode.customer.dao.TCustomerAccountMapper;
import com.bristua.barcode.customer.model.TCustomerAccount;
import com.bristua.barcode.customer.model.condition.TCustomerAccountExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/8/26.
 */
@RestController
public class GetCustomerAmtController {

    @Autowired
    private GetCustomerIdBiz getCustomerIdBiz;

    @Resource
    private TCustomerAccountMapper tCustomerAccountMapper;

    @PostMapping(value = "/customer/get/amt")
    public Result setCustomerBankPwd(){
        String customerId = getCustomerIdBiz.getCustomerId();
        TCustomerAccountExample tCustomerAccountExample = new TCustomerAccountExample();
        tCustomerAccountExample.createCriteria().andCustomerIdEqualTo(customerId);
        List<TCustomerAccount> tCustomerAccounts = tCustomerAccountMapper.selectByExample(tCustomerAccountExample);
        if(tCustomerAccounts!=null && tCustomerAccounts.size()>0){
            TCustomerAccount tCustomerAccount = tCustomerAccounts.get(0);
            Map<String,String> data = new HashMap<>();
            BigDecimal divide = new BigDecimal(tCustomerAccount.getAccountAmt()).divide(new BigDecimal(100));
            divide.setScale(2,BigDecimal.ROUND_DOWN);
            data.put("balanceAmt",String.valueOf(divide));
            BigDecimal multiply = divide.multiply(new BigDecimal(tCustomerAccount.getAccountRate()));
            BigDecimal subtract = divide.subtract(multiply);
            subtract.setScale(2,BigDecimal.ROUND_DOWN);
            data.put("availableAmt",String.valueOf(subtract));
            return HandleResultUtil.querySuccessResult(data);
        }

        return null;

    }
}
